package com.test.qpbgboot.show.controller;

import com.test.qpbgboot.base.response.JsonResult;
import com.test.qpbgboot.base.utils.BaseUtils;
import com.test.qpbgboot.show.pojo.dto.*;
import com.test.qpbgboot.show.pojo.vo.*;
import com.test.qpbgboot.show.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/v1/show")
@Slf4j
@Api(tags = "show module")
public class ShowController {

    @Autowired
    private TagService tagService;
    @Autowired
    private ShopService shopService;
    @Autowired
    private RoomService roomService;
    @Autowired
    private EscortService escortService;
    @Autowired
    private AreaService areaService;

    @GetMapping("/tag/select")
    @ApiOperation(value = "标签查询")
    public JsonResult selectTag(@Valid TagQuery tagQuery) {
        log.debug("标签查询:tagQuery={}", tagQuery);
        List<TagVO> tagVOList = tagService.tagSelect(tagQuery);
        return JsonResult.success(tagVOList);
    }

    @GetMapping("/tag/select/ids")
    @ApiOperation(value = "标签查询-根据id列表")
    public JsonResult selectTagByIds(
            @RequestParam("tagIdList")
            @ApiParam(value = "标签id列表", name = "tagIdList", required = true)
            List<Long> tagIdList) {
        log.debug("标签查询-根据id列表:tagIdList={}", tagIdList);
        List<TagVO> tagVOList = tagService.tagSelectByIdList(tagIdList);
        return JsonResult.success(tagVOList);
    }

    @PostMapping("/tag/save")
    @ApiOperation(value = "标签保存")
    public JsonResult saveTag(@Valid @RequestBody TagSaveParam tagSaveParam) {
        log.debug("标签保存:tagSaveParam={}", tagSaveParam);
        tagService.tagSave(tagSaveParam);
        return JsonResult.success();
    }

    @PostMapping("/tag/delete/{id}")
    @ApiOperation(value = "标签删除")
    public JsonResult deleteTag(@PathVariable @ApiParam(value = "标签id",
            name = "id", required = true) Long id) {
        log.debug("标签删除:id={}", id);
        tagService.tagDelete(id);
        return JsonResult.success();
    }

    @GetMapping("/shop/select")
    @ApiOperation(value = "店家查询")
    public JsonResult selectShop(@Valid @ModelAttribute ShopQuery shopQuery) {
        log.debug("店家查询:shopQuery={}", shopQuery);
        BaseUtils.removeBlank(shopQuery);
        List<ShopVO> shopVOList = shopService.shopSelect(shopQuery);
        return JsonResult.success(shopVOList);
    }

    @PostMapping("/shop/save")
    @ApiOperation(value = "店家保存")
    public JsonResult saveShop(@Valid @RequestBody ShopSaveParam shopSaveParam) {
        log.debug("店家保存:shopSaveParam={}", shopSaveParam);
        BaseUtils.removeBlank(shopSaveParam);
        shopService.shopSave(shopSaveParam);
        return JsonResult.success();
    }

    @PostMapping("/shop/log-off/{shopId}")
    @ApiOperation(value = "店家注销")
    public JsonResult logOffShop(@PathVariable @ApiParam(value = "店家id",
            name = "shopId", required = true) Long shopId) {
        log.debug("店家注销:shopId={}", shopId);
        shopService.shopLogOff(shopId);
        return JsonResult.success();
    }

    @GetMapping("/room/select")
    @ApiOperation(value = "房间查询")
    public JsonResult selectRoom(@Valid RoomQuery roomQuery) {
        log.debug("房间查询:roomQuery={}", roomQuery);
        if (roomQuery.getVisible() != null
                && roomQuery.getVisible().trim().isEmpty()) {
            roomQuery.setVisible(null);
        }
        List<RoomVO> roomVOList = roomService.roomSelect(roomQuery);
        return JsonResult.success(roomVOList);
    }

    @PostMapping("/room/save")
    @ApiOperation(value = "房间保存")
    public JsonResult saveRoom(@Valid @RequestBody RoomSaveParam roomSaveParam) {
        log.debug("房间保存:roomSaveParam={}", roomSaveParam);
        roomService.roomSave(roomSaveParam);
        return JsonResult.success();
    }

    @PostMapping("room/delete/{roomId}")
    @ApiOperation(value = "房间删除")
    public JsonResult deleteRoom(@PathVariable @ApiParam(value = "房间id",
            name = "roomId", required = true) Long roomId) {
        log.debug("房间删除:roomId={}", roomId);
        roomService.roomDelete(roomId);
        return JsonResult.success();
    }

    @GetMapping("/escort/select")
    @ApiOperation(value = "陪玩查询")
    public JsonResult selectEscort(@Valid @ModelAttribute EscortQuery escortQuery) {
        log.debug("陪玩查询:escortQuery={}", escortQuery);
        List<EscortVO> escortVOList = escortService.escortSelect(escortQuery);
        return JsonResult.success(escortVOList);
    }

    @PostMapping("/escort/save")
    @ApiOperation(value = "陪玩保存")
    public JsonResult saveEscort(@Valid @RequestBody EscortSaveParam escortSaveParam) {
        log.debug("陪玩保存:escortSaveParam={}", escortSaveParam);
        escortService.escortSave(escortSaveParam);
        return JsonResult.success();
    }

    @PostMapping("/escort/delete/{escortId}")
    @ApiOperation(value = "陪玩删除")
    public JsonResult deleteEscort(@PathVariable @ApiParam(value = "陪玩id",
    name = "escortId", required = true) Long escortId) {
        log.debug("陪玩删除:escortId={}", escortId);
        escortService.escortDelete(escortId);
        return JsonResult.success();
    }

    @GetMapping("/area/select")
    @ApiOperation(value = "地区查询")
    public JsonResult selectArea(@Valid AreaQuery areaQuery) {
        log.debug("地区查询:areaQuery={}", areaQuery);
        List<AreaVO> areaVOList = areaService.areaSelect(areaQuery);
        return JsonResult.success(areaVOList);
    }
}
